package com.clss.commandhelper.tools.eventbus;


import com.clss.commandhelper.base.BaseJson;

import org.greenrobot.eventbus.EventBus;

/**
 * 发起EventBus信息
 *
 * @author LiuV
 * @date 2017/6/13
 */

public class EventBusHelper {

    private static final String TAG = "EventBusHelper";

    public static final int RESPONSE_NULL = -11;    //返回的BaseJson为空
    public static final int LOGIN_SUCCESS = 66;     //登录成功
    public static final int LOGIN_STATUS_ERROR = -99;
    public static final int UPDATA_MY_INFO_SUCCESS = 71;
    public static final int NO_MORE_DATA = 2004;    //沒有更多數據
    public static final int LOCATION_SUCCESS = 661;    //定位成功
    public static final int HAS_NEW_MESSAGE_UNREAD = 662;    //有未读消息
    public static final int HAS_POLICE_SERVER_LIST = 663;    //有警务服务

    /**janus收到event内容为unpublished的信息*/
    public static final int JANUS_RECEIVE_UNPUBLISHED = 70;
    /**视频已从服务器终止*/
    public static final int JANUS_RECEIVE_HANG_UP = 664;

    public static void sendEventBusMsg(int code, String msg) {
        EventBus.getDefault().post(new EventBusMessage(code, msg));
    }

    public static void sendEventBusMsg(int code, String msg, long time, int type) {
        EventBus.getDefault().post(new EventBusMessage(code, msg, time, type));
    }

    public static void sendEventBusMsg(int code) {
        EventBus.getDefault().post(new EventBusMessage(code));
    }

    public static void sendEventBusMsg(String msg) {
        EventBus.getDefault().post(new EventBusMessage(msg));
    }

    public static void handleBaseJson(BaseJson baseJson) {
        if (baseJson != null) {
            if (baseJson.getCode() == 0 || baseJson.getCode() == 201) {

            } else {
                sendEventBusMsg(baseJson.getCode(), baseJson.getError());
            }
        } else {
            sendEventBusMsg(RESPONSE_NULL, "");
        }
    }
}
